﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HAC;

namespace MyDomainClustering
{
    class MyDistanceMetric : HAC.IDistanceMetric
    {
        public float GetDistance(Element ele1, Element ele2)
        {
            string id1 = ele1.Id;
            string id2 = ele2.Id;
            StringBuilder sb = new StringBuilder();
            //string key = "";
            if (id1.CompareTo(id2) < 0)
            {
                sb.Append(id1);
                sb.Append("-");
                sb.Append(id2);
                //key = id1 + "-" + id2;
            }
            else
            {
                sb.Append(id2);
                sb.Append("-");
                sb.Append(id1);
                //key = id2 + "-" + id1;
            }
            try
            {
                float similarity = Clustering.domainSimilarityRecord[sb.ToString()];
                return 1 - similarity;// 1 means large distance, 0 means very similar
            }
            catch (KeyNotFoundException)
            {
                return 1;
            }
        }
    }
}
